package com.jcp.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.jcp.entity.Parment;
import com.jcp.entity.Record;
import com.jcp.entity.Users;

@Repository
public interface PayMapper {
	//余额查询
	@Select(value="select * from Users where phoneNumber= #{phoneNumber}")
	List<Users> selectMoney(@Param(value="phoneNumber") String phoneNumber);
	//查询进出记录
	@Select(value="select Record.carNumber,Record.enter_time,Record.out_time,Record.payment_amount from Record INNER JOIN Users on Users.carNumber = Record.carNumber where Users.phoneNumber=#{phoneNumber}")
	List<Record> selectrecordbycar(@Param(value="phoneNumber") String phoneNumber); 
	
	//余额增加
	@Update(value="UPDATE  Users set remainder=remainder+#{remainder} where phoneNumber=#{phoneNumber}")
	Integer addremainder(@Param(value="remainder") double remainder,@Param(value="phoneNumber") String phoneNumber);
	
	//余额减少
	@Update(value="UPDATE  Users set Users.remainder=(Users.remainder-#{remainder}) where Users.phoneNumber=#{phoneNumber}")
	int reduceremainder(@Param(value="remainder") double remainder,@Param(value="phoneNumber") String phoneNumber);
	
	@Select(value="SELECT  Parment.paymentId,Parment.payTime,Parment.payment_amount,Parment.carNumber,Parment.paymentType FROM Parment INNER JOIN Users on Users.carNumber=Parment.carNumber where Users.carNumber=#{phoneNumber}")
	List<Parment> selectparmt(@Param(value="phoneNumber") String phoneNumber);
	
	@Update(value="UPDATE Users set Users.membership_expires_date=(#{time}) where Users.phoneNumber=#{phoneNumber}")
	int JCPhuiyuan(@Param(value="time") String time,@Param(value="phoneNumber") String phoneNumber) ;
	
	
	
	
	
}
